package com.cyzy.controller;

import com.cyzy.dao.CourseCampus;
import com.cyzy.dao.UserRole;
import com.cyzy.dto.Result;
import com.cyzy.pojo.Campus;
import com.cyzy.pojo.CourseCategory;
import com.cyzy.service.CourseManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseManageService courseManageService;

    @GetMapping("/selectAllCourseByPage")
    public Result selectAllCourse(CourseCampus courseCampus, int pageSize, int pageNum){
        System.out.println(courseManageService.selectAllCourse(courseCampus, pageSize, pageNum));
        return Result.ok().data("course", courseManageService.selectAllCourse(courseCampus, pageSize, pageNum));
    }

    @GetMapping("/selectAllCategory")
    public Result selectAllCategory(CourseCategory courseCategory){
        return Result.ok().data("categoryList",courseManageService.selectAllCategory(courseCategory));
    }

    @GetMapping("/getCourse")
    public Result getCourse(CourseCampus courseCampus) {
        List<CourseCampus> getCourse = courseManageService.getCourse(courseCampus);
        return Result.ok().data("getCourse", getCourse);
    }

    // 新增课程
    @PostMapping("/addCourse")
    public Result addCourse(@RequestBody CourseCampus courseCampus) {
        int result = courseManageService.addCourse(courseCampus);
        if (result > 0) {
            return Result.ok().message("新增成功");
        }
        return Result.error().message("新增失败");
    }

    // 修改课程
    @PutMapping("/updateCourse")
    public int updateCourse(@RequestBody CourseCampus courseCampus){
        return courseManageService.updateCourse(courseCampus);
    }

    @PutMapping("/updateCourseStatus")
    public int updateCourseStatus(@RequestBody CourseCampus courseCampus){
        return courseManageService.updateCourseStatus(courseCampus);
    }

    @PutMapping("/deleteCourse/{id}")
    public int deleteCourse(@PathVariable List<Integer> id){
        return courseManageService.deleteCourse(id);
    }




}
